package ip

import (
	"net"
	"strings"
)

// GetLocalIP 获取本机的ip
func GetLocalIP() string {
	addrs, err := net.InterfaceAddrs()
	if err != nil {
		panic(err)
	}
	for _, addr := range addrs {
		if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
			// 排除ingress服务网关地址
			if ipnet.IP.To4() != nil && !strings.HasPrefix(ipnet.IP.String(), "10.0.0") {
				return ipnet.IP.String()
			}
		}
	}
	return ""
}
